﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using SharePoint2007Migration.Attributes;

namespace SharePoint2007Migration.Managers
{
    public static class ReflectionManager
    {
        public static string DisplayObjectProperties(Object o)
        {
            StringBuilder sb = new StringBuilder();
            System.Type type = o.GetType();
            foreach (PropertyInfo p in type.GetProperties())
            {
                if (p.CanRead)
                {
                    //if (args.Any(arg => arg == "/help" || arg == "/?"))

                    object[] customAttributes = p.GetCustomAttributes(true);
                    foreach (var item in customAttributes)
                    {
                        if (item is DisplayProperty)
                        {

                            DisplayProperty dispProp = (DisplayProperty)item;

                            object obj = p.GetValue(o, null);
                            if (obj != null)
                            {
                                sb.Append(String.Concat("     ", dispProp.DisplayName, ": "));
                                sb.AppendLine(obj.ToString());
                            }
                            else sb.AppendLine(String.Concat(dispProp.DisplayName, " # Value is null"));
                        }
                    }
                }
            }
            return sb.ToString();
        }
    }
}
